package com.tanhua.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult implements Serializable {

    private Long counts = 0L;//总记录数
    private Integer pagesize;//页大小
    private Integer pages = 0;//总页数
    private Integer page;//当前页码
    private List<?> items = Collections.emptyList(); //列表
    public static  PageResult init(Integer page, Integer pagesize, Long counts, List<?> list) {
        PageResult pageResult = new PageResult();
        pageResult.page = page;
        pageResult.pagesize = pagesize;
        pageResult.items = list;
        pageResult.counts = counts;
        pageResult.pages = counts.intValue() % pagesize == 0 ? counts.intValue() / pagesize : counts.intValue() / pagesize + 1;
        return pageResult;
    }
}